<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../js/layui/css/layui.css"  media="all">
</head>
<body>
 <form  class="layui-form" id="form1">
 	<div class="layui-form-item" style="margin-top: 10px;margin-left: 10px;">
	    <div class="layui-input-inline">
	      <input type="text" name="phone" id="phone" lay-verify="required" placeholder="根据手机号码查找" autocomplete="off" class="layui-input">
		</div>
		<div class="layui-input-inline">
	      <input type="text" name="name" id="name" lay-verify="required" placeholder="根据姓名查找" autocomplete="off" class="layui-input">
		</div>
		<div>    
		  	 <button id="find"  class="layui-btn" type="button" lay-filter="find"><i class="layui-icon">&#xe615;</i></button>
		</div>
	</div>
 </form> 
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
	<button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
    <button class="layui-btn layui-btn-sm" lay-event="upd">修改</button>>
  </div>
</script>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
          
<script src="../js/layui/layui.js" charset="utf-8"></script>
<script>
var master = "";
layui.use(['table','jquery'], function(){
  var table = layui.table
  ,$ = layui.jquery;
  //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
  //详见：https://www.layui.com/doc/modules/table.html#totalRow
  table.render({
    elem: '#test'
    ,height: 'full'
    ,url:'../master/selectList'
    ,method:'post'
    ,toolbar: '#toolbarDemo'
    ,title: '用户数据表'
    ,cellMinWidth: 80
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'id', title:'工号'}
      ,{field:'name', title:'姓名'}
      ,{field:'sex', title:'性别'}
      ,{field:'age', title:'年龄'}
      ,{field:'phone', title:'手机号'}
      ,{field:'account', title:'账号'}
      ,{field:'address', title:'位置'}
      ,{field:'status', title:'状态',templet:status}
    ]]
    ,page: true
    ,id:'master'
  });
	//搜索
  $("#find").click(function(){
       table.reload('master', {
      	 where:{
      		name:$("#name").val(),
      		phone:$("#phone").val()
      	 }
       });
  });
  //工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
    	case 'add':
        var data = checkStatus.data;
	   	layer.open({
	         type: 2,
	         skin: 'layui-layer-demo', //样式类名
	         title: '新增',
	         closeBtn: 1, //不显示关闭按钮
	         anim: 2,
	         maxmin: true,
	         area: ['30%', '65%'],
	         shadeClose: true, //开启遮罩关闭
	         content: '../master/add'
	    });
      break;
      case 'upd':
        var data = checkStatus.data;
        master = data;
        layer.open({
	         type: 2,
	         skin: 'layui-layer-demo', //样式类名
	         title: '修改',
	         closeBtn: 1, //不显示关闭按钮
	         anim: 2,
	         maxmin: true,
	         area: ['30%', '65%'],
	         shadeClose: true, //开启遮罩关闭
	         content: '../master/upd'
	     });
      break;
    };
  });
});
function status(d){
	var str="";
	if(d.status=='0'){
		str="在忙";
	}
	if(d.status=='1'){
		str="空闲";
	}
	if(d.status=='2'){
		str="其他";
	}
	return str;
}
</script>
</body>
</html>